VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsNguoiDung"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private m_sTenDangNhap As String
Private m_sMatKhau As String
Private m_iMaNguoiDung As Integer
Private m_iMaLoaiNguoiDung As Integer

Public Property Get MaLoaiNguoiDung() As Integer
    MaLoaiNguoiDung = m_iMaLoaiNguoiDung
End Property

Public Property Let MaLoaiNguoiDung(ByVal iMaLoaiNguoiDung As Integer)
    m_iMaLoaiNguoiDung = iMaLoaiNguoiDung
End Property

Public Property Get MaNguoiDung() As Integer
    MaNguoiDung = m_iMaNguoiDung
End Property

Public Property Let MaNguoiDung(ByVal iMaNguoiDung As Integer)
    m_iMaNguoiDung = iMaNguoiDung
End Property

Public Property Get tendangnhap() As String
    tendangnhap = m_sTenDangNhap
End Property

Public Property Let tendangnhap(ByVal sTenDangNhap As String)
    m_sTenDangNhap = sTenDangNhap
End Property

Public Property Get matkhau() As String
    matkhau = m_sMatKhau
End Property

Public Property Let matkhau(ByVal sMatKhau As String)
    m_sMatKhau = sMatKhau
End Property

'---------------------------------------------------------------------------------------
' Procedure : SelectAll
' Date      : 27/10/2011
' Purpose   : Load danh sach tat ca record cua table co trong file du lieu
'---------------------------------------------------------------------------------------
Public Function SelectAll() As ADODB.Recordset
   On Error GoTo SelectAll_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectAll = g_ObjADOConn.Execute("SELECT * FROM NguoiDung")

   On Error GoTo 0
   Exit Function
SelectAll_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectAll of Class Module clsNguoiDung"
End Function

'---------------------------------------------------------------------------------------
' Procedure : SelectByID
' Date      : 27/10/2011
' Purpose   : Lay record cua table ung voi ma NguoiDung truyen vao
'---------------------------------------------------------------------------------------
Public Function SelectByID(ByVal ID As Integer) As ADODB.Recordset
   On Error GoTo SelectByID_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectByID = g_ObjADOConn.Execute("SELECT * FROM NguoiDung WHERE MaNguoiDung = " & ID & "")

   On Error GoTo 0
   Exit Function
SelectByID_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectByID of Class Module clsNguoiDung"
End Function

'---------------------------------------------------------------------------------------
' Procedure : SelectByTenDangNhap
' Date      : 01/11/2011
' Purpose   : Lay record cua table ung voi ten dang nhap truyen vao
'---------------------------------------------------------------------------------------
Public Function SelectByTenDangNhap(ByVal tendangnhap As String) As ADODB.Recordset
   On Error GoTo SelectByTenDangNhap_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectByTenDangNhap = g_ObjADOConn.Execute("SELECT * FROM NguoiDung WHERE TenDangNhap = '" & tendangnhap & "'")

   On Error GoTo 0
   Exit Function
SelectByTenDangNhap_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectByTenDangNhap of Class Module clsNguoiDung"
End Function

Public Function SelectByTenDangNhapMatKhau(ByVal tendangnhap As String, ByVal matkhau As String) As ADODB.Recordset
   On Error GoTo SelectByTenDangNhap_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectByTenDangNhapMatKhau = g_ObjADOConn.Execute("SELECT * FROM NguoiDung WHERE TenDangNhap = '" & tendangnhap & "' AND MatKhau = '" & matkhau & "'")

   On Error GoTo 0
   Exit Function
SelectByTenDangNhap_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectByTenDangNhap of Class Module clsNguoiDung"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Insert
' Date      : 27/10/2011
' Purpose   : Them 1 record moi vao table trong file du lieu
'---------------------------------------------------------------------------------------
Public Function Insert(ByVal objNguoiDung As clsNguoiDung) As Boolean
    
   On Error GoTo Insert_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("INSERT INTO NguoiDung(MaLoaiNguoiDung, TenDangNhap, MatKhau) " & _
                          "VALUES('" & objNguoiDung.MaLoaiNguoiDung & "', '" & objNguoiDung.tendangnhap & "', '" & objNguoiDung.matkhau & "')")
    Call CloseConnection
    Insert = True
    
   On Error GoTo 0
   Exit Function
Insert_Error:
    Insert = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Insert of Class Module clsNguoiDung"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Delete
' Date      : 27/10/2011
' Purpose   : Xoa 1 record cua table trong file du lieu
'---------------------------------------------------------------------------------------
Public Function Delete(ByVal ID As Integer) As Boolean
   On Error GoTo Delete_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("DELETE FROM NguoiDung WHERE MaNguoiDung=" & ID)
    Call CloseConnection
    Delete = True
    
   On Error GoTo 0
   Exit Function
Delete_Error:
    Delete = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Delete of Class Module clsNguoiDung"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Update
' Date      : 27/10/2011
' Purpose   : Update record cua table dua tren ID truyen vao
'---------------------------------------------------------------------------------------
Public Function Update(ByVal objNguoiDung As clsNguoiDung) As Boolean
   On Error GoTo Update_Error
    Dim sql As String
    
    sql = "UPDATE NguoiDung " & _
                          "SET MaLoaiNguoiDung = '" & objNguoiDung.MaLoaiNguoiDung & "', " & _
                              "TenDangNhap = '" & objNguoiDung.tendangnhap & "' " & _
                              "MatKhau = '" & objNguoiDung.matkhau & "' " & _
                          "WHERE MaNguoiDung = " & objNguoiDung.MaNguoiDung
    Call OpenConnection
    g_ObjADOConn.Execute (sql)
    Call CloseConnection
    Update = True

   On Error GoTo 0
   Exit Function
Update_Error:
    Update = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Update of Class Module clsNguoiDung"
End Function

